
#ifndef     __PIC16_UART_H__
#define     __PIC16_UART_H__
   
 
#define 	BAUD 				9600      
#define 	FOSC 				8000000L
#define 	NINE 				0     /* Use 9bit communication? FALSE=8bit */
#define 	REC_INTR_ENA 	1  			  /* Interrupt on the receive from the UART */

#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1

#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif

#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif

#if defined(_16F87) || defined(_16F88)
	#define RX_PIN TRISB2
	#define TX_PIN TRISB5
#elif defined(_16F627) || defined(_16F627A)
	#define RX_PIN TRISB1
	#define TX_PIN TRISB2
#elif defined(_16F690)
	#define RX_PIN TRISB5
	#define TX_PIN TRISB7
#elif defined(_16F886)
	#define RX_PIN TRISC7
	#define TX_PIN TRISC6
#endif


/* Serial initialization */
#define InitUART()\
	RX_PIN = 1;	\
   TX_PIN = 1;	  \
   RCIF = 0; 		\
   RCIE = REC_INTR_ENA; \
   SPBRG = DIVIDER;     	\
	RCSTA = (NINE_BITS|0x90);	\
	TXSTA = (SPEED|NINE_BITS|0x20)


void putchar ( char );
void puts ( const char *s );
void putsn ( unsigned char  *s, unsigned char b_num );

/* UART Receiver */
#define   UART_RECEIVE_BUFFER_SIZE		32

extern unsigned char UART_Receive_Buffer[UART_RECEIVE_BUFFER_SIZE];
extern volatile bit UART_Receive_Complete;
void UART_Receiver ( void );

#endif

